package com.burpee.dao;

import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.burpee.ui.ExerciseOrder;
import com.burpee.ui.ExerciseSchedule;

@Repository(value="exercisescheduleDao")
public class ExerciseScheduleDaoImpl implements ExerciseScheduleDao {

	
	SqlSessionTemplate sqlSessionTemplate;

	@Autowired
	public void setSessionTemplate(SqlSessionFactory sqlSessionFactory) {
		this.sqlSessionTemplate = new SqlSessionTemplate(sqlSessionFactory);
	}
	
	public List<ExerciseSchedule> list(HashMap map) {
		List<ExerciseSchedule> list = null;

		try {
			list = sqlSessionTemplate.selectList("exerciseschedulelist",map);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return list;
	}
	
	public List<ExerciseSchedule> schedulelist(ExerciseSchedule exerciseSchedule) {
		List<ExerciseSchedule> list = null;

		try {
			list = sqlSessionTemplate.selectList("exercisescheduleChoiceList",exerciseSchedule);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return list;
	}

	public ExerciseSchedule view(ExerciseSchedule exerciseSchedule) {
		ExerciseSchedule exerciseScheduleview = new ExerciseSchedule();

		try {
			exerciseScheduleview = sqlSessionTemplate.selectOne("exercisescheduleview", exerciseSchedule);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return exerciseScheduleview;
	}

	public int add(ExerciseSchedule exerciseSchedule) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.insert("exercisescheduleadd",exerciseSchedule);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public int modify(ExerciseSchedule exerciseSchedule) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("exerciseschedulemodify",exerciseSchedule);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

	public int remove(ExerciseSchedule exerciseSchedule) {
		int result = 0;

		try {
			result = (int)sqlSessionTemplate.update("exercisescheduleremove",exerciseSchedule);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return result;
	}

}
